package org.fing.edu.uy.esbadp.motor.mbean;

import javax.management.NotCompliantMBeanException;
import javax.management.StandardMBean;

import org.fing.edu.uy.esbadp.core.entity.DMAdpAdaptationRequirements;
import org.fing.edu.uy.esbadp.core.entity.DMAdpEvents;
import org.fing.edu.uy.esbadp.core.entity.DMAdpStrategies;
import org.fing.edu.uy.esbadp.core.entity.PropertiesMonitoring;
import org.fing.edu.uy.esbadp.core.interfaces.IMotorMonitorServicesMBean;
import org.fing.edu.uy.esbadp.logger.LoggerADP;
import org.fing.edu.uy.esbadp.motor.config.LoaderXMLConfig;
import org.fing.edu.uy.esbadp.motor.register.RegistryManager;
import org.fing.edu.uy.esbadp.motor.thread.ThreadProcessNotification;
import org.jboss.internal.soa.esb.assertion.AssertArgument;


public class MotorMonitorServices extends StandardMBean implements IMotorMonitorServicesMBean {

	private static java.util.logging.Logger logger = LoggerADP.getLogger(MotorMonitorServices.class.getSimpleName());

	protected MotorMonitorServices(Class<?> mbeanInterface) throws NotCompliantMBeanException {
		super(mbeanInterface);
	}
	
	@Override
	public void notifyProperties(Long serviceId, PropertiesMonitoring properties) {
		AssertArgument.isNotNull(serviceId, "serviceId");
		AssertArgument.isNotNull(properties, "properties");
		
		if(logger.isLoggable(LoggerADP.DEBUG_LEVEL)){
			logger.log(LoggerADP.DEBUG_LEVEL, "The engine monitor is a notification process for service {0}.", serviceId);
		}
		
		//process async notification
		Thread thread = new ThreadProcessNotification(serviceId, properties);
		thread.start();
	}

	@Override
	public void reloadMonitoredEvents() {
		LoaderXMLConfig cfloader = new LoaderXMLConfig();
		cfloader.loadMonitoredEvents();
	}

	@Override
	public DMAdpEvents adpEvents() {
		return RegistryManager.getInstance().getAdpEvents();
	}

	@Override
	public void reloadAdaptationRequirements() {
		LoaderXMLConfig cfloader = new LoaderXMLConfig();
		cfloader.loadAdaptationRequirements();
		
	}

	@Override
	public DMAdpAdaptationRequirements adpRequirements() {
		return RegistryManager.getInstance().getAdpRequirements();
	}

	@Override
	public void reloadStrategies() {
		LoaderXMLConfig cfloader = new LoaderXMLConfig();
		cfloader.loadStrategies();
		
	}
		
	
	@Override
	public DMAdpStrategies adpStrategies() {
		return RegistryManager.getInstance().getAdpStrategies();
	}
}
